package gel;

import static org.junit.Assert.assertTrue;
import java.awt.geom.Point2D;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import gel.test.RobotTestBed;

/**
 * Tests that Menehune moves from search mode into tracking mode and/or firing mode.
 * 
 * @author George Lee
 *
 */
public class TestMenehuneMovement extends RobotTestBed {
  /**Check that the robot moves within a certain distance of the enemy robot.*/
  boolean inStrikingDistance = false;

  /**
   * @see gel.test.RobotTestBed#getRobotNames()
   * @return The comma delimited list of robots in the match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,gel.Menehune";
  }
  
  /**
   * This test runs for 5 rounds.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 5;
  }
  
  /**
   * After each turn, check to see that we're in striking distance.
   * @param event Info about the current state of the battle.
   */
  @Override 
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot fire = event.getTurnSnapshot().getRobots()[0];
    IRobotSnapshot menehune = event.getTurnSnapshot().getRobots()[1];
    
    Point2D.Double menehuneLocation = new Point2D.Double(menehune.getX(), menehune.getY());
    Point2D.Double fireLocation = new Point2D.Double(fire.getX(), fire.getY());
    
    double distance = menehuneLocation.distance(fireLocation);
    if (distance <= Menehune.MIN_DISTANCE) {
      inStrikingDistance = true;
    }
  }
  
  /**
   * After the battle, check to see that we went to the modes.
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check inStrikingDistance", inStrikingDistance);
  }

}
